package com.zhao.service.serviceImpl;

import com.zhao.dao.SuperviserDao;
import com.zhao.pojo.Superviser;
import com.zhao.service.SuperviserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpSession;
import java.util.List;

@Service
@Transactional
public class SuperviserServiceImpl implements SuperviserService {

    @Autowired
    private SuperviserDao superviserDao;

    @Override
    public String addOneSuperviser(Superviser superviser, HttpSession session) {

        Superviser superviser1 = superviserDao.findByID(superviser.getSuperviserID(),superviser.getUniversityID());
        if(superviser1!=null){
            return "ID已经存在,添加失败";
        }
        int res = superviserDao.addOne(superviser);
        if(res != 1){
            return "添加失败";
        }

        return "success";
    }

    @Override
    public String getAll(String universityID , HttpSession session) {

        List<Superviser> superviserList = superviserDao.findAll(universityID);

        session.setAttribute("superviserList",superviserList);

        return "success";
    }
}
